www.gusucode.com > VC++ 实现多幅图像的打印-源码程序 > VC++ 实现多幅图像的打印-源码程序/code/print/printView.cpp

    //Download by http://www.NewXing.com
// printView.cpp : implementation of the CPrintView class
//

#include "stdafx.h"
#include "print.h"

#include "printDoc.h"
#include "printView.h"

#include "DlgMeaning.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CPrintView

IMPLEMENT_DYNCREATE(CPrintView, CScrollView)

BEGIN_MESSAGE_MAP(CPrintView, CScrollView)
	//{{AFX_MSG_MAP(CPrintView)
	ON_WM_LBUTTONDOWN()
	ON_WM_MOUSEMOVE()
	ON_WM_LBUTTONUP()
	ON_WM_LBUTTONDBLCLK()
	//}}AFX_MSG_MAP
	// Standard printing commands
	ON_COMMAND(ID_FILE_PRINT, CScrollView::OnFilePrint)
	ON_COMMAND(ID_FILE_PRINT_DIRECT, CScrollView::OnFilePrint)
	ON_COMMAND(ID_FILE_PRINT_PREVIEW, CScrollView::OnFilePrintPreview)
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CPrintView construction/destruction

CPrintView::CPrintView()
{
	// TODO: add construction code here

}

CPrintView::~CPrintView()
{
}

BOOL CPrintView::PreCreateWindow(CREATESTRUCT& cs)
{
	// TODO: Modify the Window class or styles here by modifying
	//  the CREATESTRUCT cs

	return CScrollView::PreCreateWindow(cs);
}

/////////////////////////////////////////////////////////////////////////////
// CPrintView drawing

void CPrintView::OnDraw(CDC* pDC)
{
	CPrintDoc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);
	// TODO: add draw code for native data here
/*	if(pDoc->m_flag>=1)
	{

		OLE_XSIZE_HIMETRIC hmWidth; 
		OLE_YSIZE_HIMETRIC hmHeight; 

		pDoc->pPic->get_Width(&hmWidth); 
		pDoc->pPic->get_Height(&hmHeight); 

		double fX,fY; 
		CPoint m_point;
		fX =(double)hmWidth; 
		fY =(double)hmHeight; 
		if(fY/fX>0.75)
		{
			fX=300.0*fX/fY;
			fY=300.0;
			m_point=CPoint((400-(int)fX)/2,0);
		}
		else
		{
			fY=400.0*fY/fX;
			fX=400.0;
			m_point=CPoint(0,-(300-(int)fY)/2);
		}

		ASSERT(pDoc->pPic->Render(*pDC,m_point.x,m_point.y,(DWORD)fX,(DWORD)(-fY),0,
				hmHeight,hmWidth,-hmHeight,NULL)==NULL);
	}
*/
	if(pDoc->m_flag>=1)
	{
		OLE_XSIZE_HIMETRIC hmWidth; 
		OLE_YSIZE_HIMETRIC hmHeight; 
		double fX,fY; 
		CPoint m_point;

		for(int i=1;i<=pDoc->m_flag;i++)
		{
			if(i==1)
			{
				pDoc->pPic->get_Width(&hmWidth); 
				pDoc->pPic->get_Height(&hmHeight); 
			}
			if(i==2)
			{
				pDoc->pPic_add1->get_Width(&hmWidth); 
				pDoc->pPic_add1->get_Height(&hmHeight); 
			}
			else if(i==3)
			{
				pDoc->pPic_add2->get_Width(&hmWidth); 
				pDoc->pPic_add2->get_Height(&hmHeight); 
			}
			else if(i==4)
			{
				pDoc->pPic_add3->get_Width(&hmWidth); 
				pDoc->pPic_add3->get_Height(&hmHeight); 
			}
			else if(i==5)
			{
				pDoc->pPic_add4->get_Width(&hmWidth); 
				pDoc->pPic_add4->get_Height(&hmHeight); 
			}
			else if(i==6)
			{
				pDoc->pPic_add5->get_Width(&hmWidth); 
				pDoc->pPic_add5->get_Height(&hmHeight); 
			}

			fX =(double)hmWidth; 
			fY =(double)hmHeight;

			if(fY/fX>0.75)
			{
				fX=300.0*fX/fY;
				fY=300.0;
				m_point=CPoint((400-(int)fX)/2,0);
			}
			else
			{
				fY=400.0*fY/fX;
				fX=400.0;
				m_point=CPoint(0,-(300-(int)fY)/2);
			}
			if(i==1)
				ASSERT(pDoc->pPic->Render(*pDC,m_point.x,m_point.y,(DWORD)fX,(DWORD)(-fY),0,
				hmHeight,hmWidth,-hmHeight,NULL)==NULL);
			else if(i==2)
				ASSERT(pDoc->pPic_add1->Render(*pDC,400+m_point.x,m_point.y,(DWORD)fX,(DWORD)(-fY),0,
				hmHeight,hmWidth,-hmHeight,NULL)==NULL);
			else if(i==3)
				ASSERT(pDoc->pPic_add2->Render(*pDC,m_point.x,-350+m_point.y,(DWORD)fX,(DWORD)(-fY),0,
				hmHeight,hmWidth,-hmHeight,NULL)==NULL);
			else if(i==4)
				ASSERT(pDoc->pPic_add3->Render(*pDC,400+m_point.x,-350+m_point.y,(DWORD)fX,(DWORD)(-fY),0,
				hmHeight,hmWidth,-hmHeight,NULL)==NULL);
			else if(i==5)
				ASSERT(pDoc->pPic_add3->Render(*pDC,m_point.x,-700+m_point.y,(DWORD)fX,(DWORD)(-fY),0,
				hmHeight,hmWidth,-hmHeight,NULL)==NULL);
			else if(i==6)
				ASSERT(pDoc->pPic_add3->Render(*pDC,400+m_point.x,-700+m_point.y,(DWORD)fX,(DWORD)(-fY),0,
				hmHeight,hmWidth,-hmHeight,NULL)==NULL);
		}		
	}	
	for(int i=0;i<pDoc->m_flag;i++)
		pDC->TextOut(100+i%2*400,-(305+i/2*350),pDoc->m_string[i]);

}

void CPrintView::OnInitialUpdate()
{
	CScrollView::OnInitialUpdate();

	CSize sizeTotal;
	// TODO: calculate the total size of this view
	sizeTotal.cx=800;
	sizeTotal.cy=1050;
	SetScrollSizes(MM_LOENGLISH, sizeTotal);
}

/////////////////////////////////////////////////////////////////////////////
// CPrintView printing

BOOL CPrintView::OnPreparePrinting(CPrintInfo* pInfo)
{
	// default preparation
	return DoPreparePrinting(pInfo);
}

void CPrintView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
	// TODO: add extra initialization before printing
}

void CPrintView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
	// TODO: add cleanup after printing
}

/////////////////////////////////////////////////////////////////////////////
// CPrintView diagnostics

#ifdef _DEBUG
void CPrintView::AssertValid() const
{
	CScrollView::AssertValid();
}

void CPrintView::Dump(CDumpContext& dc) const
{
	CScrollView::Dump(dc);
}

CPrintDoc* CPrintView::GetDocument() // non-debug version is inline
{
	ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CPrintDoc)));
	return (CPrintDoc*)m_pDocument;
}
#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// CPrintView message handlers

void CPrintView::OnPrint(CDC* pDC, CPrintInfo* pInfo) 
{
	// TODO: Add your specialized code here and/or call the base class
	pDC->SetWindowOrg(-12,100);
	OnDraw(pDC);
	CScrollView::OnPrint(pDC, pInfo);
	//CScrollView::OnPrint(pDC, pInfo);
}



void CPrintView::OnLButtonDblClk(UINT nFlags, CPoint point) 
{
	CPrintDoc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);
	// TODO: Add your message handler code here and/or call default
	point.y+=this->GetScrollPos(SB_VERT);
	point.x+=this->GetScrollPos(SB_HORZ);

/*	CString str;
	str.Format("%d   %d",point.x,point.y);
	AfxMessageBox(str);
*/
	CDlgMeaning m_dlg;
	int m_num=-1;

	if(point.x>=0&&point.x<=320)
	{
		if(point.y>=0&&point.y<=240)
		{
			m_num=0;
			m_dlg.m_meaning=pDoc->m_string[0];	
		}
		else if(point.y>=290&&point.y<=520)
		{
			m_num=2;
			m_dlg.m_meaning=pDoc->m_string[2];
		}
		else if(point.y>=575&&point.y<=810)
		{
			m_num=4;
			m_dlg.m_meaning=pDoc->m_string[4];
		}
	}
	else if(point.x>=330&&point.x<=640)
	{
		if(point.y>=0&&point.y<=240)
		{
			m_num=1;
			m_dlg.m_meaning=pDoc->m_string[1];	
		}
		else if(point.y>=290&&point.y<=520)
		{
			m_num=3;
			m_dlg.m_meaning=pDoc->m_string[3];
		}
		else if(point.y>=575&&point.y<=810)
		{
			m_num=5;
			m_dlg.m_meaning=pDoc->m_string[5];
		}
	}

	if(m_num!=-1&&m_num<pDoc->m_flag)
	{
		if(m_dlg.DoModal()==IDOK)
		{
			pDoc->m_string[m_num]=m_dlg.m_meaning;
			pDoc->UpdateAllViews(NULL);
		}
	}
	//CScrollView::OnLButtonDblClk(nFlags, point);
}